using SM.core;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace SM.sys
{
	public class frmGroup : Form
	{
		private Group objGroup = new Group();
		private IContainer components = null;
		private GroupBox groupBox1;
		private ListView lsvGroup;
		private ColumnHeader columnHeader1;
		private ColumnHeader columnHeader3;
		private Button btnAdd;
		private Button btnEdit;
		private Button btnSave;
		private Button btnDel;
		private Button btnClose;
		private Label label1;
		private TextBox txtGID;
		private Label label2;
		private TextBox txtGName;
		private ListView lsvPer;
		private ColumnHeader columnHeader4;
		private ColumnHeader columnHeader5;
		private CheckBox ckbStatus;
		private ColumnHeader columnHeader6;
		private Label label3;
		public frmGroup()
		{
			this.InitializeComponent();
		}
		private void frmAccount_Load(object sender, EventArgs e)
		{
			this.objGroup.loadToListView(this.lsvGroup);
			this.objGroup.loadPerToListView(this.lsvPer);
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void btnAdd_Click(object sender, EventArgs e)
		{
			this.txtGName.Enabled = true;
			this.ckbStatus.Enabled = true;
			this.txtGID.Text = "0";
			this.txtGName.Text = "";
			this.ckbStatus.Checked = false;
			this.txtGName.Focus();
			this.btnEdit.Enabled = false;
			this.btnDel.Enabled = false;
			this.btnSave.Enabled = true;
		}
		private void lsvAccount_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.txtGName.Text = this.lsvGroup.Items[this.lsvGroup.FocusedItem.Index].SubItems[1].Text;
			this.txtGID.Text = this.lsvGroup.Items[this.lsvGroup.FocusedItem.Index].SubItems[0].Text;
			if (this.lsvGroup.Items[this.lsvGroup.FocusedItem.Index].SubItems[2].Text == "1")
			{
				this.ckbStatus.Checked = true;
			}
			else
			{
				this.ckbStatus.Checked = false;
			}
			this.objGroup.checkPer(this.txtGID.Text, this.lsvPer);
			this.btnEdit.Enabled = true;
			this.btnDel.Enabled = true;
			this.txtGID.Enabled = false;
			this.txtGName.Enabled = false;
			this.ckbStatus.Enabled = false;
		}
		private void btnEdit_Click(object sender, EventArgs e)
		{
			this.txtGName.Enabled = true;
			this.txtGName.Focus();
			this.btnDel.Enabled = false;
			this.btnSave.Enabled = true;
			this.ckbStatus.Enabled = true;
		}
		private void btnSave_Click(object sender, EventArgs e)
		{
			if (this.txtGName.Text == "")
			{
				MessageBox.Show("Nhập vào tên hợp lệ của nhóm tài khoản!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.txtGName.Focus();
			}
			else
			{
				int gStatus;
				if (this.ckbStatus.Checked)
				{
					gStatus = 1;
				}
				else
				{
					gStatus = 0;
				}
				string text = "";
				for (int i = 0; i < this.lsvPer.Items.Count; i++)
				{
					if (this.lsvPer.Items[i].Checked)
					{
						text = text + "\"" + this.lsvPer.Items[i].SubItems[0].Text + "\",";
					}
				}
				if (text != "")
				{
					text = text.Remove(text.Length - 1);
				}
				if (this.objGroup.action(int.Parse(this.txtGID.Text), this.txtGName.Text, text, gStatus) == 0)
				{
					this.btnEdit.Enabled = true;
					this.btnDel.Enabled = true;
					this.txtGID.Enabled = false;
					this.txtGName.Enabled = false;
					this.ckbStatus.Enabled = false;
					this.btnSave.Enabled = false;
					this.objGroup.loadToListView(this.lsvGroup);
				}
				else
				{
					MessageBox.Show("Có lỗi xảy ra trong quá trình lưu thông tin!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				}
			}
		}
		private void btnDel_Click(object sender, EventArgs e)
		{
			if (this.txtGID.Text != "1" && this.txtGID.Text != "2")
			{
				if (MessageBox.Show("Bạn có thật sự muốn xoá nhóm tài khoản được chọn không!", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
				{
					if (!this.objGroup.checkExist(this.txtGID.Text))
					{
						if (this.objGroup.delItem(int.Parse(this.txtGID.Text)) == 0)
						{
							this.btnDel.Enabled = true;
							this.txtGID.Enabled = false;
							this.txtGName.Enabled = false;
							this.ckbStatus.Enabled = false;
							this.btnSave.Enabled = false;
							this.objGroup.loadToListView(this.lsvGroup);
						}
					}
					else
					{
						MessageBox.Show("Bạn phải xóa hết tài khoản thuộc nhóm này trước !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
					}
				}
			}
			else
			{
				MessageBox.Show("Bạn không thể xóa nhóm tài khoản mặc định này!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			}
		}
		private void frmGroup_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}
		private void frmGroup_SizeChanged(object sender, EventArgs e)
		{
			this.columnHeader3.Width = this.lsvGroup.Width - 20;
			this.columnHeader5.Width = this.lsvPer.Width - this.columnHeader4.Width - 20;
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(frmGroup));
			this.groupBox1 = new GroupBox();
			this.ckbStatus = new CheckBox();
			this.label2 = new Label();
			this.txtGName = new TextBox();
			this.lsvPer = new ListView();
			this.columnHeader4 = new ColumnHeader();
			this.columnHeader5 = new ColumnHeader();
			this.label1 = new Label();
			this.txtGID = new TextBox();
			this.lsvGroup = new ListView();
			this.columnHeader1 = new ColumnHeader();
			this.columnHeader3 = new ColumnHeader();
			this.columnHeader6 = new ColumnHeader();
			this.btnAdd = new Button();
			this.btnEdit = new Button();
			this.btnSave = new Button();
			this.btnDel = new Button();
			this.btnClose = new Button();
			this.label3 = new Label();
			this.groupBox1.SuspendLayout();
			base.SuspendLayout();
			this.groupBox1.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.groupBox1.BackColor = Color.Transparent;
			this.groupBox1.Controls.Add(this.ckbStatus);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.txtGName);
			this.groupBox1.Location = new System.Drawing.Point(329, 4);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new Size(565, 54);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Thông tin";
			this.ckbStatus.AutoSize = true;
			this.ckbStatus.BackColor = Color.Transparent;
			this.ckbStatus.Enabled = false;
			this.ckbStatus.Location = new System.Drawing.Point(483, 24);
			this.ckbStatus.Name = "ckbStatus";
			this.ckbStatus.Size = new Size(77, 19);
			this.ckbStatus.TabIndex = 4;
			this.ckbStatus.Text = "Kích hoạt";
			this.ckbStatus.UseVisualStyleBackColor = false;
			this.label2.AutoSize = true;
			this.label2.Location = new System.Drawing.Point(25, 25);
			this.label2.Name = "label2";
			this.label2.Size = new Size(69, 15);
			this.label2.TabIndex = 3;
			this.label2.Text = "Tên nhóm :";
			this.txtGName.BackColor = Color.White;
			this.txtGName.Enabled = false;
			this.txtGName.Location = new System.Drawing.Point(98, 22);
			this.txtGName.Name = "txtGName";
			this.txtGName.Size = new Size(379, 21);
			this.txtGName.TabIndex = 1;
			this.lsvPer.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.lsvPer.BorderStyle = BorderStyle.FixedSingle;
			this.lsvPer.CheckBoxes = true;
			this.lsvPer.Columns.AddRange(new ColumnHeader[]
			{
				this.columnHeader4,
				this.columnHeader5
			});
			this.lsvPer.Cursor = Cursors.Hand;
			this.lsvPer.FullRowSelect = true;
			this.lsvPer.GridLines = true;
			this.lsvPer.Location = new System.Drawing.Point(329, 64);
			this.lsvPer.Name = "lsvPer";
			this.lsvPer.Size = new Size(565, 497);
			this.lsvPer.TabIndex = 5;
			this.lsvPer.UseCompatibleStateImageBehavior = false;
			this.lsvPer.View = View.Details;
			this.columnHeader4.Text = "Số hiệu";
			this.columnHeader4.Width = 77;
			this.columnHeader5.Text = "Tên chức năng";
			this.columnHeader5.Width = 223;
			this.label1.AutoSize = true;
			this.label1.Location = new System.Drawing.Point(404, 180);
			this.label1.Name = "label1";
			this.label1.Size = new Size(55, 15);
			this.label1.TabIndex = 1;
			this.label1.Text = "Số hiệu :";
			this.txtGID.BackColor = Color.White;
			this.txtGID.Enabled = false;
			this.txtGID.Location = new System.Drawing.Point(352, 180);
			this.txtGID.Name = "txtGID";
			this.txtGID.ReadOnly = true;
			this.txtGID.Size = new Size(80, 21);
			this.txtGID.TabIndex = 0;
			this.lsvGroup.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left);
			this.lsvGroup.BorderStyle = BorderStyle.FixedSingle;
			this.lsvGroup.Columns.AddRange(new ColumnHeader[]
			{
				this.columnHeader1,
				this.columnHeader3,
				this.columnHeader6
			});
			this.lsvGroup.Cursor = Cursors.Hand;
			this.lsvGroup.FullRowSelect = true;
			this.lsvGroup.GridLines = true;
			this.lsvGroup.Location = new System.Drawing.Point(6, 64);
			this.lsvGroup.Name = "lsvGroup";
			this.lsvGroup.Size = new Size(317, 497);
			this.lsvGroup.TabIndex = 11;
			this.lsvGroup.UseCompatibleStateImageBehavior = false;
			this.lsvGroup.View = View.Details;
			this.lsvGroup.SelectedIndexChanged += new EventHandler(this.lsvAccount_SelectedIndexChanged);
			this.columnHeader1.Text = "STT";
			this.columnHeader1.Width = 0;
			this.columnHeader3.Text = "Tên gọi";
			this.columnHeader3.Width = 218;
			this.columnHeader6.Width = 0;
			this.btnAdd.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnAdd.BackColor = Color.FromArgb(192, 255, 255);
			this.btnAdd.Cursor = Cursors.Hand;
			this.btnAdd.FlatStyle = FlatStyle.System;
			this.btnAdd.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnAdd.Location = new System.Drawing.Point(6, 567);
			this.btnAdd.Name = "btnAdd";
			this.btnAdd.Size = new Size(80, 28);
			this.btnAdd.TabIndex = 6;
			this.btnAdd.Text = "&Thêm mới";
			this.btnAdd.UseVisualStyleBackColor = false;
			this.btnAdd.Click += new EventHandler(this.btnAdd_Click);
			this.btnEdit.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnEdit.BackColor = Color.FromArgb(192, 255, 255);
			this.btnEdit.Cursor = Cursors.Hand;
			this.btnEdit.Enabled = false;
			this.btnEdit.FlatStyle = FlatStyle.System;
			this.btnEdit.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnEdit.Location = new System.Drawing.Point(87, 567);
			this.btnEdit.Name = "btnEdit";
			this.btnEdit.Size = new Size(80, 28);
			this.btnEdit.TabIndex = 7;
			this.btnEdit.Text = "&Sửa đổi";
			this.btnEdit.UseVisualStyleBackColor = false;
			this.btnEdit.Click += new EventHandler(this.btnEdit_Click);
			this.btnSave.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnSave.BackColor = Color.FromArgb(192, 255, 255);
			this.btnSave.Cursor = Cursors.Hand;
			this.btnSave.Enabled = false;
			this.btnSave.FlatStyle = FlatStyle.System;
			this.btnSave.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnSave.Location = new System.Drawing.Point(168, 567);
			this.btnSave.Name = "btnSave";
			this.btnSave.Size = new Size(80, 28);
			this.btnSave.TabIndex = 8;
			this.btnSave.Text = "&Ghi nhận";
			this.btnSave.UseVisualStyleBackColor = false;
			this.btnSave.Click += new EventHandler(this.btnSave_Click);
			this.btnDel.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnDel.BackColor = Color.FromArgb(192, 255, 255);
			this.btnDel.Cursor = Cursors.Hand;
			this.btnDel.Enabled = false;
			this.btnDel.FlatStyle = FlatStyle.System;
			this.btnDel.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnDel.Location = new System.Drawing.Point(249, 567);
			this.btnDel.Name = "btnDel";
			this.btnDel.Size = new Size(80, 28);
			this.btnDel.TabIndex = 9;
			this.btnDel.Text = "&Xoá bỏ";
			this.btnDel.UseVisualStyleBackColor = false;
			this.btnDel.Click += new EventHandler(this.btnDel_Click);
			this.btnClose.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.btnClose.BackColor = Color.FromArgb(192, 255, 255);
			this.btnClose.Cursor = Cursors.Hand;
			this.btnClose.FlatStyle = FlatStyle.System;
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
            ////this.btnClose.Image = (Image)componentResourceManager.GetObject("btnClose.Image");
			//this.btnClose.ImageAlign = ContentAlignment.MiddleLeft;
			this.btnClose.Location = new System.Drawing.Point(804, 567);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(90, 28);
			this.btnClose.TabIndex = 10;
			this.btnClose.Text = "Th&oát   [ ESC ]";
			this.btnClose.UseVisualStyleBackColor = false;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			this.label3.Font = new Font("Arial", 9.75f, FontStyle.Bold, GraphicsUnit.Point, 0);
			this.label3.Location = new System.Drawing.Point(12, 11);
			this.label3.Name = "label3";
			this.label3.Size = new Size(311, 47);
			this.label3.TabIndex = 12;
			this.label3.Text = "QUẢN LÝ NHÓM TÀI KHOẢN";
			this.label3.TextAlign = ContentAlignment.MiddleCenter;
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			base.ClientSize = new Size(900, 600);
			base.Controls.Add(this.lsvPer);
			base.Controls.Add(this.label3);
			base.Controls.Add(this.btnClose);
			base.Controls.Add(this.btnDel);
			base.Controls.Add(this.txtGID);
			base.Controls.Add(this.btnSave);
			base.Controls.Add(this.btnEdit);
			base.Controls.Add(this.btnAdd);
			base.Controls.Add(this.lsvGroup);
			base.Controls.Add(this.groupBox1);
			base.Controls.Add(this.label1);
			this.Cursor = Cursors.Hand;
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			//base.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("$this.Icon");
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			base.MaximizeBox = false;
			base.MinimizeBox = false;
			base.Name = "frmGroup";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = " .: Nhóm tài khoản";
			base.Load += new EventHandler(this.frmAccount_Load);
			base.SizeChanged += new EventHandler(this.frmGroup_SizeChanged);
			base.KeyDown += new KeyEventHandler(this.frmGroup_KeyDown);
			this.groupBox1.ResumeLayout(false);
			this.groupBox1.PerformLayout();
			base.ResumeLayout(false);
			base.PerformLayout();
		}
	}
}
